package com.lss.e_array;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

/**
 * @author lss
 * @description  缺失的第一个正数
 * @createDate 2024/12/13-9:50
 */
public class lc_41 {
    public static void main(String[] args) {
        int[] nums = new int[]{1};
        firstMissingPositive(nums);
    }
    /**
     *
     * @param nums
     * @return
     */
    public static int firstMissingPositive(int[] nums) {
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 1; i <= nums.length + 1; i++) {
            map.put(i,0);
        }
        for(int x : nums){
            if (map.containsKey(x)){
                map.remove(x);
            }
        }
        Set<Integer> set = map.keySet();
        if (set.size() == 1){
            return (Integer) set.toArray()[0];
        }
        return set.stream().min((a,b) -> a - b).get();
    }
}
